<?php

/**
 * This is the model class for table "uploads".
 *
 * The followings are the available columns in table 'uploads':
 * @property integer $id
 * @property string $alt
 * @property string $original_name
 * @property string $file_name
 * @property integer $is_image
 * @property integer $width
 * @property integer $height
 * @property integer $filesize
 * @property string upload_date
 * @property string $owner_type
 * @property integer $id_owner
 * @property integer $enabled
 */
class Uploads extends ExtActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Uploads the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function _tableName()
	{
		return 'uploads';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('filesize, owner_type', 'required'),
			array('is_image, width, height, filesize, enabled, id_owner', 'numerical', 'integerOnly'=>true),
			array('alt, original_name, file_name, owner_type', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			// array('id, alt, original_name, file_name, is_image, width, height, filesize, owner_id, enabled', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(			
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'alt' => 'Alt',
			'original_name' => 'Original Name',
			'file_name' => 'File Name',
			'is_image' => 'Is Image',
			'width' => 'Width',
			'height' => 'Height',
			'filesize' => 'Filesize',
			'owner_id' => 'Owner',
			'enabled' => 'Enabled',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('alt',$this->alt,true);
		$criteria->compare('original_name',$this->original_name,true);
		$criteria->compare('file_name',$this->file_name,true);
		$criteria->compare('is_image',$this->is_image);
		$criteria->compare('width',$this->width);
		$criteria->compare('height',$this->height);
		$criteria->compare('filesize',$this->filesize);
		$criteria->compare('owner_id',$this->owner_id,true);
		$criteria->compare('enabled',$this->enabled);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}